<template>
  <div class="notFound">
    <div class="img">
      <img src="/images/notfound.png" alt="" />
    </div>
    <div class="text">
      <span>抱歉，您所访问的页面小的暂未找到哦~</span><br />
      <span>{{ timer }}s后返回上一级</span>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onUnmounted } from 'vue';
import { useRouter } from 'vue-router';

// 创建响应式数据
const timer = ref(5);
const router = useRouter();

// 定时器逻辑
const intervalId = setInterval(() => {
  timer.value--;
  if (timer.value <= 0) {
    clearInterval(intervalId);
    router.back();
  }
}, 1000);

// 组件卸载时清除定时器，避免内存泄漏
onUnmounted(() => {
  clearInterval(intervalId);
});
</script>

<style scoped>
.notFound {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  .img {
    width: 80%;

    img {
      width: 100%;
      height: 450px;
    }
  }
  .text {
    width: 100%;
    text-align: center;
    color: #666;
    font-size: 30px;
  }
}
</style>